package com.moon.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayStartAuctionConfig {

    //死信部分
    @Bean
    public FanoutExchange deadLetterExchange(){
        return new FanoutExchange("deadLetterAuctionExchange");
    }

    @Bean
    public Queue deadLetterQueue(){
        return new Queue("deadLetterAuctionQueue");
    }

    @Bean
    public Binding deadLetterBinding(){
        return BindingBuilder.bind(deadLetterQueue()).to(deadLetterExchange());
    }


    //normal部分
    @Bean
    public DirectExchange normalExchange(){
        return new DirectExchange("delayAuctionExchange");
    }

    //正常队列不能有消费者
    @Bean
    public Queue normalQueue(){
        return QueueBuilder.durable("delayAuctionQueue")
                .deadLetterExchange(deadLetterExchange().getName())
                .deadLetterRoutingKey("xxxxxx")
                .ttl(24*3600*1000)  //延迟 1 天
                .build();

    }

    @Bean
    public Binding normalBinding(){
        return BindingBuilder.bind(normalQueue())
                .to(normalExchange())
                .with("closeAuction");

    }


}
